﻿using UnityEngine;
using System.Collections;

public class ModDamage : IModBase
{
    private float lossHpRedTime = 0;

    public ModDamage(OwnerObj ownerObj) : base(ownerObj)
    {

    }

    public void BeDamaged(int hp)
    {
        lossHpRedTime = 0.2f;

        UnityGameObject unityGameObject = ownerObj.Get<IUnitObject>().GetUnityGameObject();

        if (null != unityGameObject)
        {
            unityGameObject.SetSpriteRendererColor(Color.red);
        }
    }

    public override void Update(float deltaTime)
    {
        base.Update(deltaTime);

        if (lossHpRedTime > 0)
        {
            lossHpRedTime -= deltaTime;
        }
        else
        {
            UnityGameObject unityGameObject = ownerObj.Get<IUnitObject>().GetUnityGameObject();
            if (null != unityGameObject)
            {
                if (Color.red == unityGameObject.GetSpriteRendererColor())
                {
                    unityGameObject.SetSpriteRendererColor(Color.white);
                }
            }
            
        }
    }
}
